home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Applications
/
NeuroSim 1.0
/
.cp
/
CParamsDialog.cp
< prev
next >
Wrap
Text File
|
1996-02-19
|
7KB
|
237 lines
// ===========================================================================
// CParamsDialog.cp ©1996 Timo Eloranta
// ===========================================================================
// This class handles the dialog where the user can view and modify the
// parameters of a new neural net. CParamsDialog is derived from LDialogBox -
// a PowerPlant window class with default (OK) and Cancel buttons.
#include "CParamsDialog.h"
#include <PP_Messages.h> // cmd_About
#include <UDesktop.h>
#include "NS_Utils.h" // SignedIntField keyfilter
// ---------------------------------------------------------------------------
// • CParamsDialog
//
// Called by: CParamsDialog::CreateParamsDialogStream
// ---------------------------------------------------------------------------
// Constructor. Call the base class with the LStream object reference.
CParamsDialog::CParamsDialog(
LStream *inStream )
: LDialogBox( inStream )
{
}
// ---------------------------------------------------------------------------
// • CreateParamsDialogStream [static]
//
// Called by: CNeuroSimApp::ObeyCommand (indirect call)
// ---------------------------------------------------------------------------
// Return a new ParamsDialog object initialized using data from a Stream.
CParamsDialog *
CParamsDialog::CreateParamsDialogStream(
LStream *inStream)
{
return ( new CParamsDialog( inStream ) );
}
// ---------------------------------------------------------------------------
// • InitDialog
//
// Called by: CNeuroSimApp::ObeyCommand
// ---------------------------------------------------------------------------
// Initialize all the controls inside the dialog.
void
CParamsDialog::InitDialog()
{
mSizeCapt = (LCaption *) this -> FindPaneByID( capt_Size );
mSizeSlider = (HorzSlider *) this -> FindPaneByID( slid_Size );
mMinEdit = (LEditField *) this -> FindPaneByID( edit_Qty_Min );
mMaxEdit = (LEditField *) this -> FindPaneByID( edit_Qty_Max );
mAvg_X_Edit = (LEditField *) this -> FindPaneByID( edit_Avg_x );
mDev_X_Edit = (LEditField *) this -> FindPaneByID( edit_Dev_x );
mAvg_Y_Edit = (LEditField *) this -> FindPaneByID( edit_Avg_y );
mDev_Y_Edit = (LEditField *) this -> FindPaneByID( edit_Dev_y );
mFactoryButton = (LStdButton *) this -> FindPaneByID( but_Factory );
if ( mFactoryButton)
mFactoryButton -> AddListener( this );
mMinEdit -> Enable();
mMinEdit -> Activate();
mMinEdit -> SelectAll();
if ( mSizeSlider ) {
mSizeSlider -> SetPicts( pict_Base, pict_Slider, pict_Selected );
mSizeSlider -> SetMinMax( 2, 14 );
mSizeSlider -> SetValueMessage( slid_Size );
if ( mSizeSlider -> MakeSlider() )
mSizeSlider -> AddListener( this );
else
delete mSizeSlider;
}
// The average values can be negative and since PowerPlant
// doesn't have a built-in keyfilter for allowing only
// numbers and the '-' character, we set our custom keyfilter
// here "manually". The filter is defined in NS_Utils.h.
mAvg_X_Edit -> SetKeyFilter( SignedIntField );
mAvg_Y_Edit -> SetKeyFilter( SignedIntField );
}
// ---------------------------------------------------------------------------
// • SetValues
//
// Called by: CNeuroSimApp::ObeyCommand
// CParamsDialog::SetDefaultValues
// ---------------------------------------------------------------------------
// Set the controls of the dialog to the values given in "inParams".
void
CParamsDialog::SetValues( SGenParams &inParams )
{
SetSizeValue( inParams.size );
mSizeSlider -> SetSliderValue( inParams.size );
mMinEdit -> SetValue( inParams.qtyMin );
mMaxEdit -> SetValue( inParams.qtyMax );
mAvg_X_Edit -> SetValue( inParams.xLengthAvg );
mDev_X_Edit -> SetValue( inParams.xLengthDev );
mAvg_Y_Edit -> SetValue( inParams.yLengthAvg );
mDev_Y_Edit -> SetValue( inParams.yLengthDev );
}
// ---------------------------------------------------------------------------
// • SetSizeValue
//
// Called by: CParamsDialog::SetValues
// CParamsDialog::ListenToMessage
// ---------------------------------------------------------------------------
// Transform the given (numeric) net size N to a string of type "N x N"
// and set this string to the caption field beside the slider.
void
CParamsDialog::SetSizeValue( Int16 inValue )
{
LStr255 theNbrString( (Int32) inValue );
LStr255 theString( theNbrString );
theString.Append( "\p x " );
theString.Append( theNbrString );
mSizeCapt -> SetDescriptor( theString );
}
// ---------------------------------------------------------------------------
// • GetValues
//
// Called by: CNeuroSimApp::ObeyCommand
// ---------------------------------------------------------------------------
// Read the new values of the controls. Do also some validity checking.
void
CParamsDialog::GetValues( SGenParams &outParams )
{
outParams.size = mSizeSlider -> GetSliderValue();
outParams.xLengthAvg = mAvg_X_Edit -> GetValue();
outParams.xLengthDev = mDev_X_Edit -> GetValue();
outParams.yLengthAvg = mAvg_Y_Edit -> GetValue();
outParams.yLengthDev = mDev_Y_Edit -> GetValue();
outParams.qtyMin = mMinEdit -> GetValue();
outParams.qtyMax = mMaxEdit -> GetValue();
// Minimum can not be bigger than maximum...
// If it is, set the maximum to be equal to minimum
// and show an alert box to the silly user!
if ( outParams.qtyMax < outParams.qtyMin ) {
outParams.qtyMax = outParams.qtyMin;
LStr255 theParam0( (Int32) outParams.qtyMin );
UDesktop::Deactivate();
::ParamText( theParam0, "\p", "\p", "\p");
::StopAlert( ALRT_MinMax, nil );
UDesktop::Activate();
}
}
// ---------------------------------------------------------------------------
// • ListenToMessage
//
// Called by: LBroadcaster::BroadcastMessage
// ---------------------------------------------------------------------------
// Respond to messages from Broadcasters
void
CParamsDialog::ListenToMessage(
MessageT inMessage,
void *ioParam )
{
switch ( inMessage ) {
case slid_Size:
if ( mSizeCapt ) {
SetSizeValue( *(Int32 *) ioParam );
mSizeCapt -> Draw( NULL );
}
break;
case msg_FactorySettings:
SetDefaultValues();
break;
default:
LDialogBox::ListenToMessage( inMessage, ioParam );
break;
}
}
// ---------------------------------------------------------------------------
// • SetDefaultValues
//
// Called by: CParamsDialog::ListenToMessage
// ---------------------------------------------------------------------------
// This function is used when the user pushes the "Factory Settings" button.
void
CParamsDialog::SetDefaultValues()
{
SGenParams theDefaults = { DEFAULT_LENGTH_X_AVG, DEFAULT_LENGTH_Y_AVG,
DEFAULT_LENGTH_X_DEV, DEFAULT_LENGTH_Y_DEV,
DEFAULT_NET_SIZE,
DEFAULT_QTY_MIN, DEFAULT_QTY_MAX };
SetValues( theDefaults );
}
// ---------------------------------------------------------------------------
// • FindCommandStatus
//
// Called by: LCommander::ProcessCommandStatus
// ---------------------------------------------------------------------------
// Disable all menu commands except cmd_About
void
CParamsDialog::FindCommandStatus(
CommandT inCommand,
Boolean &outEnabled,
Boolean& /* outUsesMark */,
Char16& /* outMark */,
Str255 /* outName */)
{
outEnabled = false;
if (inCommand == cmd_About) {
outEnabled = true;
}
}